package com.ruoyi.web.controller.erp;

import com.ruoyi.system.domain.Customer;
import com.ruoyi.system.domain.PurchaseOrder;
import com.ruoyi.system.domain.SalesOrder;
import com.ruoyi.system.domain.Supplier;
import com.ruoyi.system.service.ICustomerService;
import com.ruoyi.system.service.ISupplierSerService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/erp/supplier")
public class SupplierController {

    @Resource
    ISupplierSerService iSupplierSerService;

    /**
     * 查询客户列表
     *
     * @param supplier 客户信息
     * @return 客户集合
     */
    @PostMapping("/selectSupplierList")
    public List<Supplier> selectSupplierList(@RequestBody Supplier supplier){
        List<Supplier> list=iSupplierSerService.selectSupplierList(supplier);
        return  list;
    }

    /**
     * 查询客户详细信息
     *
     * @param supplierId 客户ID
     * @return 客户信息
     */
    @PostMapping("/selectSupplierById")
    public Supplier selectSupplierById(Long supplierId){
        Supplier supplier=iSupplierSerService.selectSupplierById(supplierId);
        return supplier;
    }

    /**
     * 查询客户关联的销售单
     *
     * @param supplierId 客户ID
     * @return 销售单列表
     */
    @PostMapping("/selectSalesOrdersBySupplierId")
    public List<PurchaseOrder> selectSalesOrdersBySupplierId(Long supplierId) {
        List<PurchaseOrder> list=iSupplierSerService.selectSalesOrdersBySupplierId(supplierId);
        return list;
    }

    /**
     * 新增客户
     *
     * @param supplier 客户信息
     * @return 结果
     */
    @PostMapping("/insertSupplier")
    public Map insertSupplier(@RequestBody Supplier supplier){
        Map map=new HashMap();
        int rows=iSupplierSerService.insertSupplier(supplier);
        if (rows>0){
            String msg="添加成功";
            map.put("msg",msg);
        }else {
            String msg="添加失败";
            map.put("msg",msg);
        }
        return map;
    }

    /**
     * 修改客户
     *
     * @param supplier 客户信息
     * @return 结果
     */
    @PostMapping("/updateSupplier")
    public Map updateSupplier(@RequestBody Supplier supplier){
        Map map=new HashMap();
        int rows=iSupplierSerService.updateSupplier(supplier);
        if (rows>0){
            String msg="修改成功";
            map.put("msg",msg);
        }else {
            String msg="修改失败";
            map.put("msg",msg);
        }
        return map;
    }

    /**
     * 删除客户信息
     *
     * @param supplierId 客户ID
     * @return 结果
     */
    @PostMapping("/deleteSupplierById")
    public Map deleteSupplierById(Long supplierId){
        Map map=new HashMap();
        int rows=iSupplierSerService.deleteSupplierById(supplierId);
        if (rows>0){
            String msg="删除成功";
            map.put("msg",msg);
        }else {
            String msg="删除失败";
            map.put("msg",msg);
        }
        return map;
    }

    /**
     * 批量删除客户信息
     *
     * @param supplierIds 需要删除的客户ID
     * @return 结果
     */
    @PostMapping("/deleteSupplierByIds")
    public Map deleteSupplierByIds(Long[] supplierIds){
        Map map=new HashMap();
        int rows=iSupplierSerService.deleteSupplierByIds(supplierIds);
        if (rows==supplierIds.length){
            String msg="修改成功";
            map.put("msg",msg);
        }else {
            String msg="修改失败";
            map.put("msg",msg);
        }
        return map;
    }
}
